import { Button, Popconfirm, Tooltip } from 'antd';
import { DeleteOutlined } from '@ant-design/icons';
import { ManageAPI } from '../common/type';
import { ColumnsRenderFun } from '@/common';
import { getKeyRouter, tooltipLength } from '@/utils';
import { history } from 'umi';

/**
 * 折旧记录 - 弹窗 - 表格配置
 * */
export const GatherModalManageTableColumns = ({ onDeleteFun, onSkipFun }) => {
  return [
    {
      title: '账期',
      dataIndex: 'depreciationDate',
      key: 'depreciationDate',
      width: 200,
      render: (text, record) => <a onClick={() => onSkipFun(record)}>{text}</a>,
    },
    {
      title: '制单时间',
      dataIndex: 'createDay',
      key: 'createDay',
      width: 200,
    },
    {
      title: '制单人',
      dataIndex: 'operatorName',
      key: 'operatorName',
      width: 200,
    },
    {
      title: '折旧/摊销总金额',
      dataIndex: 'totalDepreciationValue',
      key: 'totalDepreciationValue',
      width: 200,
    },
    {
      title: '操作',
      dataIndex: 'operation',
      key: 'operation',
      width: 120,
      render: (text: string | null, record: Record<string, any>) => {
        return (
          <div style={{ display: 'flex' }}>
            <Popconfirm placement="bottom" title={'确认删除此折旧记录！'} onConfirm={() => onDeleteFun(record)} okText="确认" cancelText="取消">
              <Button className="manageColorRedBtn" type={'link'} size="small" danger icon={<DeleteOutlined />}>
                删除
              </Button>
            </Popconfirm>
          </div>
        );
      },
    },
  ];
};

/**
 * 管理页表格配置
 * */
export const DetailManageTableSwitch = (curRes: Record<string, any>, operateFuns: ManageAPI.IOperateAPI) => {
  return [
    {
      title: '资产编号',
      dataIndex: 'assetCode',
      key: 'assetCode',
      // fixed: 'left',
      width: 150,
      // unDrag: true,
      visible: true,
      sorter: (a: any, b: any) => (a?.assetCode > b?.assetCode ? 1 : -1),
      render: (text: string | null, record: Record<string, any>) => ColumnsRenderFun({ text, isTooltip: true }),
    },
    {
      title: '资产名称',
      dataIndex: 'assetName',
      key: 'assetName',
      width: 150,
      visible: true,
      sorter: (a: any, b: any) => (a?.assetName > b?.assetName ? 1 : -1),
      // render: (text: string | null, record: Record<string, any>) => ColumnsRenderFun({ text, isTooltip: true }),
      render: (text, record) => {
        return (
          <>
            <Tooltip title={tooltipLength(text, 50)}>
              <a
                onClick={() => {
                  history.push({
                    pathname: `/assetInfo/detail/:${getKeyRouter()}${getKeyRouter()}`,
                    state: {
                      pageType: 'detail',
                      id: record?.materialOrAssetId,
                      returnPathName: history.location.pathname,
                    },
                  });
                }}
              >
                {text || '--'}
              </a>
            </Tooltip>
          </>
        );
      },
    },
    {
      title: '资产分类',
      dataIndex: 'assetClassName',
      key: 'assetClassName',
      width: 150,
      visible: true,
      sorter: (a: any, b: any) => (a?.assetClassName > b?.assetClassName ? 1 : -1),
      render: (text: string | null, record: Record<string, any>) => ColumnsRenderFun({ text, isTooltip: true }),
    },
    {
      title: '记账日期',
      dataIndex: 'entryDate',
      key: 'entryDate',
      width: 150,
      visible: true,
      sorter: (a: any, b: any) => (a?.entryDate > b?.entryDate ? 1 : -1),
      // render: (text: string | null, record: Record<string, any>) => ColumnsRenderFun({text, isTooltip: true })
      render: (text, record) => {
        return <>{text?.split(' ')?.[0] || '--'}</>;
      },
    },
    {
      title: '资产原值',
      dataIndex: 'newAssetValue',
      key: 'newAssetValue',
      width: 150,
      visible: true,
      sorter: (a: any, b: any) => (a?.newAssetValue > b?.newAssetValue ? 1 : -1),
      render: (text: string | null, record: Record<string, any>) => ColumnsRenderFun({ text, isTooltip: true }),
    },
    {
      title: '上期累计折旧',
      dataIndex: 'lastAssetValue',
      key: 'lastAssetValue',
      width: 150,
      visible: true,
      sorter: (a: any, b: any) => (a?.lastAssetValue > b?.lastAssetValue ? 1 : -1),
      render: (text: string | null, record: Record<string, any>) => ColumnsRenderFun({ text, isTooltip: true }),
    },
    {
      title: '本期折旧额',
      dataIndex: 'deprecitionValue',
      key: 'deprecitionValue',
      width: 150,
      visible: true,
      sorter: (a: any, b: any) => (a?.deprecitionValue > b?.deprecitionValue ? 1 : -1),
      render: (text: string | null, record: Record<string, any>) => ColumnsRenderFun({ text, isTooltip: true }),
    },
    // {
    //     title: '操作',
    //     dataIndex: 'operation',
    //     key: 'operation',
    //     width: 230,
    //     visible: true,
    //     unDrag: true,
    //     fixed: 'right',
    //     render: (text: string | null, record: Record<string, any>) => {
    //         return <div style={{ display: 'flex' }}>{Operation(curRes, operateFuns, record)}</div>;
    //     },
    // },
  ];
};
